<%@ page import="org.jeecgframework.web.util.StaticValue" %>
<%@ page language="java" import="java.util.*" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>零件采购订单</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
    <style>
        .text-area-readonly {
            width: 100%;
        }
    </style>
</head>
<body>
<t:formvalid formid="formobj" dialog="false" usePlugin="password" layout="table"
             action="cbsQuotationController.do?doAdd" beforeSubmit="checkTaskHandle" tiptype="3" callback="subCallBack">
    <input type="hidden" name="state" id="state">
    <input type="hidden" name="noteId" value="${bus.id }">
    <input type="hidden" name="taskId" value="${task.id }">
    <input type="hidden" name="instId" value="${instId }">
    <div class="subtitle">
        <p>客户信息</p>
        <table class="nobordertable noborder">
            <tr>
                <td class="al_r" width="20%">
                    <label>采购单编号:</label>
                </td>
                <td width="20%">
                        ${bus.procurementNo}
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                    <label>客户类型:</label>
                </td>
                <td width="20%">
                        ${bus.clientType == 0?'客户':'第三方' }
                </td>
                <td class="al_r" width="30%">
                    <c:if test="${bus.clientType != 0 }"><label>采购方:</label></c:if>
                </td>
                <td width="30%">
                    <c:if test="${bus.clientType != 0 }">${bus.procurement.departname }</c:if>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <label>影院名称:</label>
                </td>
                <td>
                        ${bus.cinema.name }
                </td>
                <td class="al_r">
                    <label>影院地址:</label>
                </td>
                <td>
                    <span id="cinemaAddr">${bus.cinema.address }</span>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <label>所属机构:</label>
                </td>
                <td>
                    <span id="departName">${bus.cinema.belongOrg.departname }</span>
                </td>
                <td class="al_r">
                    <label>影院所属省市:</label>
                </td>
                <td>
						<span id="city">
							${bus.cinema.province.territoryName}
							<c:if test="${not empty bus.cinema.city }">,${bus.cinema.city }</c:if>
						</span>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <label>联系人名称:</label>
                </td>
                <td>
                        ${bus.contactName }
                </td>
                <td class="al_r">
                    <label>联系人电话:</label>
                </td>
                <td>
                    <span id="phone">${bus.contactPhone }</span>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <label>联系人邮箱:</label>
                </td>
                <td>
                    <span id="mail">${bus.contactMail }</span>
                </td>
                <td class="al_r">
                    <label>传真:</label>
                </td>
                <td>
                    <span id="fax">${bus.contactFax }</span>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <c:if test="${bus.clientType == 0 }"><label>服务地点:</label></c:if>
                </td>
                <td>
                    <c:if test="${bus.clientType == 0 }">${bus.servicePlace }</c:if>
                </td>
                <td class="al_r">
                    <c:if test="${bus.clientType == 0 }"><label>是否需要上门服务:</label></c:if>
                </td>
                <td>
                    <c:if test="${bus.clientType == 0 }">${bus.isOnsiteServices eq '0'?'否':'是' }</c:if>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <label>保修期:</label>
                </td>
                <td colspan="3">
                    <textarea class="text-area-readonly" rows="3" readonly>${bus.warranty }</textarea>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <c:if test="${bus.clientType == 0 }"><label>服务前提:</label></c:if>
                </td>
                <td colspan="3">
                    <c:if test="${bus.clientType == 0 }"><textarea class="text-area-readonly" rows="3"
                                                                   readonly>${bus.servicesPremise }</textarea></c:if>
                </td>
            </tr>
            <tr>
                <td class="al_r">
                    <c:if test="${bus.clientType != 0 }"><label>备注:</label></c:if>
                </td>
                <td colspan="3">
                    <c:if test="${bus.clientType != 0 }">${bus.comment }</c:if>

                </td>
            </tr>
        </table>
    </div>
    <c:if test="${not empty bus.invoice}">
        <div class="subtitle" id="invoiceDiv">
            <p>发票信息</p>

            <table class="nobordertable noborder">
                <tr class="zy">
                    <td class="al_r" width="20%">
                        <label>发票抬头:</label>
                    </td>
                    <td width="20%">
                            ${bus.invoice.invoiceTitle}
                    </td>
                    <td class="al_r" width="20%">
                        <label>税号:</label>
                    </td>
                    <td width="20%">
                            ${bus.invoice.clientTaxnum}
                    </td>

                </tr>
                <tr class="zy">
                    <td class="al_r" width="20%">
                        <label>银行名称:</label>
                    </td>
                    <td width="30%">
                            ${bus.invoice.clientBankname}
                    </td>
                    <td class="al_r">
                        <label>银行卡账号:</label>
                    </td>
                    <td>
                            ${bus.invoice.clientBankaccount}
                    </td>
                </tr>
            </table>
        </div>
    </c:if>
    <div class="subtitle">
        <p>申请信息</p>
        <table class="nobordertable noborder">
            <tr>
                <td class="al_r" width="20%"><label>服务类型:</label></td>
                <td width="20%">零件采购</td>
                <td class="al_r" width="30%"><label>状态:</label></td>
                <td width="30%">
                    <c:if test="${bus.state eq '0' }">待处理</c:if>
                    <c:if test="${bus.state eq '1' }">处理中</c:if>
                    <c:if test="${bus.state eq '2' }">已完成</c:if>
                    <c:if test="${bus.state eq '3' }">已取消</c:if>
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%"><label>申请时间:</label></td>
                <td width="20%"><fmt:formatDate value="${bus.createDate }" pattern="yyyy-MM-dd HH:mm"/></td>
                <td class="al_r" width="30%"><label>来源:</label></td>
                <td width="30%">${bus.source eq '1'?'PC':'微信' }</td>
            </tr>
            <tr>
                <td class="al_r" width="20%"><label>最后更新时间:</label></td>
                <td width="20%"><fmt:formatDate value="${bus.updateDate }" pattern="yyyy-MM-dd HH:mm"/></td>
                <td class="al_r" width="30%"><label></label></td>
                <td width="30%"></td>
            </tr>
            <tr>
                <td class="al_r" width="20%"><label>服务描述:</label></td>
                <td colspan="3">
                    <textarea class="text-area-readonly" rows="2" cols="105" readonly>${bus.servicesDes }</textarea>
                </td>
            </tr>
        </table>
    </div>

    <div class="subtitle">
        <p>订购明细</p> &nbsp;
    </div>
    <table style="margin-top: 20px; line-height: 35px;" cellpadding="0" cellspacing="1" class="formtable"
           id="partInfoTab">
        <tr align="center">
            <td width="120px">配件号</td>
            <td width="120px">中文描述</td>
            <td width="120px">单位</td>
            <td width="120px">数量</td>
        </tr>
        <c:forEach items="${bus.partList }" var="part" varStatus="a">
            <tr align="center" style="background-color: #FFFFFF;">
                <td>${part.partInfo.partNo }</td>
                <td>${part.partInfo.chineseDes }</td>
                <td>${part.partInfo.marketUnit }</td>
                <td>${part.num }</td>
            </tr>
        </c:forEach>
    </table>

    <div class="subtitle">
        <p>相关设备</p> &nbsp;
    </div>
    <table style="margin-top: 20px; line-height: 35px;" cellpadding="0" cellspacing="1" class="formtable"
           id="equipmentTab">
        <tr align="center">
            <td>设备SN</td>
            <td>型号</td>
            <td>机型</td>
            <td>发货日期</td>
            <td>安装日期</td>
            <td>保期截至日期</td>
        </tr>

        <c:forEach items="${bus.paertEsList }" var='paertEs'>
            <tr align="center" style="background-color: #FFFFFF;">
                <td>${paertEs.equipmentSpare.sn }</td>
                <td>${paertEs.equipmentSpare.item }</td>
                <td>${paertEs.equipmentSpare.type.typeDesc }</td>
                <td><fmt:formatDate value="${paertEs.equipmentSpare.sendDate }" pattern="yyyy-MM-dd"/></td>
                <td><fmt:formatDate value="${paertEs.equipmentSpare.installDate }" pattern="yyyy-MM-dd"/></td>
                <td><fmt:formatDate value="${paertEs.equipmentSpare.repairEndDate }" pattern="yyyy-MM-dd"/></td>
            </tr>
        </c:forEach>
    </table>
    <c:if test="${isDetail eq '2' && bus.state ne '3' && empty csa}">
        <div class="subtitle quotationTital">
            <p>报价单版本</p> &nbsp;
        </div>
        <table style="margin-top: 20px; line-height: 35px;" cellpadding="0" cellspacing="1" class="formtable"
               id="quotationTable">
            <tr align="center">
                <td>报价单编号</td>
                <td>创建人</td>
                <td>创建日期</td>
                <td>状态</td>
                <td>总计</td>
            </tr>

            <c:forEach items="${bus.quotationList }" var='quotation'>
                <c:if test="${quotation.state ne '4' }">
                    <tr align="center" style="background-color: #FFFFFF;" class="quotation_list_tr">
                        <td><a style="color:blue;text-decoration: underline"
                               href="cbsQuotationController.do?goApproval&busId=${quotation.id}&isDetail=3">${quotation.quotationNum }</a>
                        </td>
                        <td>${quotation.createName }</td>
                        <td><fmt:formatDate value="${quotation.createDate }" pattern="yyyy-MM-dd HH:mm"/></td>
                        <td>
                            <c:if test="${quotation.state eq '0'}">待处理</c:if>
                            <c:if test="${quotation.state eq '1'}">处理中</c:if>
                            <c:if test="${quotation.state eq '2'}">已完成</c:if>
                            <c:if test="${quotation.state eq '3'}">已取消</c:if>
                        </td>
                        <td>¥<fmt:formatNumber value="${quotation.total }" type="number"/></td>
                    </tr>
                </c:if>
            </c:forEach>
        </table>
    </c:if>
    <div class="subtitle">
        <p>审批记录</p> &nbsp;
    </div>
    <table style="margin-top: 20px; line-height: 35px;" cellpadding="0" cellspacing="1" class="formtable">
        <tr align="center">
            <td>审批人</td>
            <td>审批时间</td>
            <td width="70%">操作结果</td>
        </tr>

        <c:forEach items="${recordList }" var='record'>
            <tr align="center" style="background-color: #FFFFFF;">
                <td>${record.tsUser.realName }</td>
                <td><fmt:formatDate value="${record.createDate }" pattern="yyyy-MM-dd HH:mm"/></td>
                <td>${record.remark }</td>
            </tr>
        </c:forEach>
    </table>
</t:formvalid>
<c:if test="${isDetail ne '2' }">
    <div style="text-align: center;margin: 50px;">
        <a class="easyui-linkbutton" onclick="save(1)">创建报价单</a>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <a class="easyui-linkbutton" onclick="transferredWin('csa')">转CSA报价</a>
        <%--<a class="easyui-linkbutton" onclick="save(0)">CSA报价</a>--%>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <a class="easyui-linkbutton" onclick="transferredWin('hd')">转派</a>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <a class="easyui-linkbutton" onclick="needReject()">取消</a>
    </div>
</c:if>
</body>
<script type="text/javascript">


    $(function () {
        if ($('.quotation_list_tr').length == 0) {
            $('#quotationTable').remove();
            $('.quotationTital').remove();
        }
    })


    function needReject() {
        var url = "cbsProcurementNoteController.do?goRejectPage&url=cbsInspectionAppointmentController.do?closeFlow-taskId=${task.id }-busId=${bus.id}-instId=${instId}";
        openRejectWin(url);
    }

    function openRejectWin(url) {
        W.$.dialog({
            content: 'url:' + url,
            lock: true,
            width: 500,
            //zIndex:1990,
            height: 200,
            parent: windowapi,
            title: '原因',
            opacity: 0.3,
            cache: false,
            ok: function () {
                iframe = this.iframe.contentWindow;
                iframe.$('#formobj').submit();
                return false;
            },
            cancelVal: '关闭',
            cancel: true /*为true等价于function(){}*/
        }).zindex();
    }


    function checkTaskHandle() {
        var taskId = '${task.id}';
        $.ajax({
            url: "cbsProcurementNoteController.do?checkTaskHandle",    //请求的url地址
            dataType: "json",   //返回格式为json
            async: false, //请求是否异步，默认为异步，这也是ajax重要特性
            data: {"taskId": taskId},    //参数值
            type: "post",   //请求方式
            success: function (data) {
                if (data.msg == 'n') {
                    top.tip("操作失败,该任务已被办理");
                    //刷新列表
                    var win = frameElement.api.opener;
                    win.reloadTable();
                    frameElement.api.close();
                    return false;
                } else {
                    return true;
                }
            }
        });
    }

    function transferredWin(type) {
        var taskId = '';
        var url = "cbsProcurementNoteController.do?goNodeTransferred&taskId=${task.id }&busId=${bus.id}&instId=${instId}&type="+type;
        W.$.dialog({
            content: 'url:' + url,
            lock: true,
            width: type=='hd'?500:300,
            //zIndex:1990,
            height: type=='hd'?220:80,
            parent: windowapi,
            title: "填写转派信息",
            opacity: 0.3,
            cache: false
        }).zindex();
    }

    function save(type) {
        $('#state').val(type);
        //如果是客户订单，设备的BP为中影（两个BP）或者横店时，不可以由HD生成报价单，只能转为CSA报价
        var clientType = '${bus.clientType}';
        if (type == 1 && clientType == 0) {
            $.post('cbsProcurementNoteController.do?getEsDepart', {busId: '${bus.id}'}, function (data) {
                if (data == '\"z\"' || data == '\"h\"') {
                    top.tip('该设备为中影或横店,不可以由HD生成报价单，只能转为CSA报价');
                } else {
                    $('#formobj').submit();
                }
            });
        } else {
            $('#formobj').submit();
        }

    }

    function subCallBack(data) {
        //提示
        top.tip(data.msg);
        //刷新列表
        var win = frameElement.api.opener;
        win.reloadTable();
        //需要CSA报价  关闭当前窗口
        if ($('#state').val() == 0) {
            frameElement.api.close();
        } else {
            //自动跳转到报价单页面
            var url = "cbsProcurementNoteController.do?goApproval&taskId=" + data.obj.taskId + "&busId=" + data.obj.busId + "&instId=" + data.obj.instId;
            window.location.href = url;
        }
    }
</script>